"""
判断 token是否过期
公共类
date :2021-01-05
"""


from . import  redisPool
class CheckToken(object):
    def __init__(self):
        pass
    def  saveRedis(self,key,value):
        pool =redisPool.pool
        pool.set(key,value,ex=3600)

    def islogin(self,token):
        if token is None or token =='':
            return False
        result = redisPool.pool.get(token)
        if result :
            # 重新刷新了下过期时间
            result = str(result, encoding = "utf8")
            #print(result)
            key = result.split('^')[0]
            user_name = result.split('^')[1]
            self.saveRedis( key ,result)
            # 返回用户名
            return   user_name
        else:
            return False
